package com.tadpole.music.view.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.tadpole.music.R;


/**
 * Created by SunYan
 * on 2020/5/11.
 */
public class ShareDialog extends BaseDialog implements View.OnClickListener {
    private IShare iShare ;
    private LinearLayout ll_wx_friend;
    private LinearLayout ll_pyq;
    private LinearLayout ll_save_img;
    private TextView tv_cancel_share;

    public ShareDialog(@NonNull Context context) {
        super(context);
    }

    public ShareDialog(@NonNull Context context, int themeResId) {
        super(context,themeResId);
        initView();
    }

    protected ShareDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private void initView(){
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(getOwnerActivity().LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.share_dialog,
                null);
        ll_wx_friend = view.findViewById(R.id.ll_wx_friend);
        ll_pyq = view.findViewById(R.id.ll_pyq);
        tv_cancel_share = view.findViewById(R.id.tv_cancel_share);
        ll_save_img = view.findViewById(R.id.ll_save_img);
        ll_wx_friend.setOnClickListener(this);
        ll_pyq.setOnClickListener(this);
        tv_cancel_share.setOnClickListener(this);
        ll_save_img.setOnClickListener(this);
        setContentView(view);
        getWindow().setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }



    public void setShareListener(IShare iShare) {
        this.iShare = iShare;
    }

    @Override
    public void show() {
        super.show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_wx_friend:
                iShare.getShareMode(1);
                break;
            case R.id.ll_pyq:
                iShare.getShareMode(2);
                break;
            case R.id.ll_save_img:
                iShare.getShareMode(3);
                break;
            case R.id.tv_cancel_share:
                iShare.getShareMode(4);
                break;
        }
    }


    public interface IShare{
        void getShareMode(int mode);
    }
}
